package cn.itsource.org.controller;

import cn.itsource.basic.domain.AjaxResult;
import cn.itsource.basic.domain.BaseQuery;
import cn.itsource.basic.util.GetUserInfoUtil;
import cn.itsource.basic.util.PageList;
import cn.itsource.org.domain.Department;
import cn.itsource.org.domain.Employee;
import cn.itsource.org.mapper.EmployeeMapper;
import cn.itsource.org.service.EmployeeService;
import cn.itsource.org.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.persistence.Id;
import java.util.List;

//@Controller + @ResponseBody
@RestController
@RequestMapping("empl")
/**
 * @Api 作用在类上 value 里面填写的是当前类的文档描述
 */
@Api(value = "部门管理的接口文档",description = "部门管理的接口文档")
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;

    @ApiOperation(value = "查询所有", notes = "查询所有")

    @GetMapping("/findall")
    public List<Employee> findall(){
        return employeeService.findAll();
    }

    @ApiOperation(value = "单个查询", notes = "单个查询")
    @GetMapping("/findOne/{id}")
    public Employee findOne(@PathVariable Long id){
        return employeeService.findOne(id);
    }

    @ApiOperation(value = "高级分页查询", notes = "高级分页查询")
    @PostMapping("/findPage")
    public PageList<Employee> findPage(@RequestBody BaseQuery baseQuery){
        return employeeService.findPage(baseQuery,"username");
    }

    @ApiOperation(value = "单个删除", notes = "单个删除")
    @GetMapping("/delete")
    public void delete(Long id){
        employeeService.delete(id);
    }

    @ApiOperation(value = "批量删除", notes = "批量删除")
    @PostMapping("/deleteBatch")
    public void deleteBatch(@RequestBody List<Long> ids){
        employeeService.deleteBatch(ids);
    }

    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    public void insert(@RequestBody Employee employee){
        employeeService.insert(employee);
    }

    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/update")
    public void update(@RequestBody Employee employee){
        employeeService.update(employee);
    }

    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/login")
    public AjaxResult login(@RequestBody Employee employee){

        return employeeService.login(employee);
    }

    @GetMapping("findByshopId")
    public List<Employee> findByShopId(){
        Long shopId = GetUserInfoUtil.getShopId();
        return employeeService.findByShopId(shopId);
    }


}
